<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.partner.prepay.role.form.Menu"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>菜单编辑</title>
		<%@ include file="/easyprepay/jsp/common/head.jsp"%>
		<%@ taglib uri="/easyprepay" prefix="easy"%>
		<script type="text/javascript">
    	function getReturn(){
    		location.href="<%=basePath%>userRole.do?method=viewAllMenu&";
    	}
    	function addChildMenu(mid,menuName){
    	
    		var value=""; 
    		var list =document.getElementsByName("childMenu");
    		
    		for (var i=0;i <list.length;i++ ){ 
				if(list[i].checked){
					value=value+list[i].value + ",";
				}
				
			} 
   		location.href="<%=basePath%>userRole.do?method=addChild&childMenuId="+value+"&menuId="+mid+"&menuName="+menuName;		
    		
    	}
    	function delChildMenu(childMenuId,childMenuName,menuName,menuId){
    	if (confirm("您确定要删除"+" "+childMenuName+"?")){
				
				location.href="<%=basePath%>userRole.do?method=delChildMenu&childMenuId="+childMenuId+"&menuName="+menuName+"&menuId="+menuId;
			}else{
				
			}
    	}
    	</script>

	</head>

	<body>


		<%
			String menuName = (String) request.getAttribute("menuName");

			String menuId = (String) request.getAttribute("menuId");
		%>
		<%=menuName%>设置
		<hr>

		<table border=1 width=100%>

			<%
				//获取子菜单集合
				List<Function> childMenu = (List<Function>) request
						.getAttribute("childMenu");
				List<Menu> childById = (List<Menu>) request
						.getAttribute("childById");
				int s = childMenu.size();
				int c = childById.size();
				
				for (int i = 0; i < s; i++) {
			%>
			<td>
				<input type="checkbox" value="<%=childMenu.get(i).getId()%>"
					name="childMenu"
					<%
					 	for(int j = 0;j<c;j++){
					 	 if(childMenu.get(i).getId().equalsIgnoreCase(childById.get(j).getFunctionId())){
					 	
						%>
					checked="true" <%
					}
					 	}
					%>><%=childMenu.get(i).getFunctionName()%>
			<td>
				<%
					if ((i + 1) % 5 == 0) {
				%>
			
			<tr>
				<%
					}
					}
				%>
			
			<tr>
				<td colspan="10" align="right">
					<%
						String mid = (String) request.getAttribute("menuId");
					%>

					<input type="button" value="返回" onclick="getReturn()">
					<input type="button" value="添加子菜单"
						onclick='addChildMenu("<%=mid%>","<%=menuName %>")'>
				</td>

			</tr>
		</table>


	</body>
</html>
